package controller

import (
	"gin-easy/pkg/code"
	"gin-easy/pkg/response"
	"gin-easy/service"
	"github.com/gin-gonic/gin"
	"net/http"
)

type Register struct {
	Name     string `json:"name" binding:"required"`
	Password string `json:"password" binding:"required"`
	Phone    string `json:"phone" binding:"required"`
}

// UserRegister 用户注册/**
func UserRegister(c *gin.Context) {
	//数据校验
	var r Register
	if err := c.ShouldBindJSON(&r); err != nil {
		response.ResponseJson(c, http.StatusInternalServerError, code.ERROR, err.Error())
		return
	}
	//注册
	userService := service.User{Phone: r.Phone, Password: r.Password, Name: r.Name}
	if res := userService.UserRegister(); !res {
		response.ResponseJson(c, http.StatusInternalServerError, code.ERROR, nil)
		return
	}
	response.ResponseJson(c, http.StatusOK, code.SUCCESS, nil)
}
